Soru & Cevap

!!Binary XML file line #6: error initiating class fragment

05.08.2014 - 08:08

arkadaşlar sorudaki gibi hata alıyrm aramadım yer kalmadı sorunun çözümünü bulamadm bide sizin le paylaşmak istedim.Sorunu kısaca anlatmak gerekrse ekteki resimdede var hiç sorunsuz fragmentlerim açılıyr hatta haritayı açtım fragmentte açılıyor.Ancak haritanın olduğu fragmente 2. kere tıkladığım da hata alıyrm hata baktığımda logcat te bana  " View rootView=inflater.inflate(R.layout.fragment_photos, container, false);" i gösteriyyr burada patlıyr uygulama

MapsFragment.java

[code]


public class MapsFragment extends Fragment {
    Button btnRefresh;
    private GoogleMap googleHarita;
String id;
static int success;
// Progress Dialog
private ProgressDialog pDialog;

// JSON parser class
JSONParser jsonParser = new JSONParser();

// single product url
private static final String url_product_detials = "http://stackcuriosity.com/hosting/android_create_db_user_info/get_product_details.php";


    // url to delete product
private static final String url_delete_product = "http://stackcuriosity.com/hosting/android_create_db_user_info/delete_product.php";

// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_PRODUCT = "product";
private static final String TAG_PID = "id";
private static final String TAG_NAME = "name";
private static final String TAG_PRICE = "address";
private static final String TAG_LAT = "lat";
private static final String TAG_LNG = "lng";

private static final String TAG_TYPE = "type";
private static int idAl=0;
    public MapsFragment(){}
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        
       View rootView=inflater.inflate(R.layout.fragment_photos, container, false);
       if (Build.VERSION.SDK_INT >= 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }

 if (googleHarita == null) {
            // Try to obtain the map from the SupportMapFragment.
            FragmentActivity baseActivity = (FragmentActivity) getActivity();
            googleHarita = ((SupportMapFragment)baseActivity.getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
            Log.i("zms","zms hata 5");
            if (googleHarita != null) {
                
                //İstanbul, Kız Kulesi olsun.
                Log.i("zms","zms Hata 6: ");
                LatLng istanbulKoordinat = new LatLng(41.021161,29.004065);
                LatLng benimKordi=new LatLng(40.9858505, 29.051649);
                Log.i("zms","zms Hata 7: ");
               
                
                googleHarita.addMarker(new MarkerOptions().position(istanbulKoordinat).title("Kız Kulesi"));
                googleHarita.moveCamera(CameraUpdateFactory.newLatLngZoom(istanbulKoordinat, 13));   
                googleHarita.addMarker(new MarkerOptions().position(benimKordi).title("Marmara Üniversitesi"));
                Log.i("zms","zms Hata 8: ");
                
               // googleHarita.addMarker(new MarkerOptions().position(WebServisKonum).title(TAG_TYPE));
                Log.i("zms","zms Hata 9: ");
            }
        }}
        Log.i("zms","zms hata 2");
       
    
          
    // save button
    

        
        return rootView;
        
    }

[/code]

Burasıda Fragmentleri ateşledim FragmentAcitivity Calssım

[code]


public class MainActivity extends FragmentActivity {
    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle mDrawerToggle;

    // nav drawer title
    private CharSequence mDrawerTitle;

    // used to store app title
    private CharSequence mTitle;

    // slide menu items
    private String[] navMenuTitles;
    private TypedArray navMenuIcons;

    private ArrayList<NavDrawerItem> navDrawerItems;
    private NavDrawerListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mTitle = mDrawerTitle = getTitle();

        // load slide menu items
        navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);

        // nav drawer icons from resources
        navMenuIcons = getResources()
                .obtainTypedArray(R.array.nav_drawer_icons);

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.list_slidermenu);

        navDrawerItems = new ArrayList<NavDrawerItem>();

        // adding nav drawer items to array
        // Home
        navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
        // Find People
        navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
        // Photos
        navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
        // Communities, Will add a counter here
        navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1), true, "22"));
        // Pages
        navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
        // What's hot, We  will add a counter here
        navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1), true, "50+"));
        

        // Recycle the typed array
        navMenuIcons.recycle();

        mDrawerList.setOnItemClickListener(new SlideMenuClickListener());

        // setting the nav drawer list adapter
        adapter = new NavDrawerListAdapter(getApplicationContext(),navDrawerItems);
        mDrawerList.setAdapter(adapter);

        // enabling action bar app icon and behaving it as toggle button
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);

        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                R.drawable.ic_drawer, //nav menu toggle icon
                R.string.app_name, // nav drawer open - description for accessibility
                R.string.app_name // nav drawer close - description for accessibility
        ) {
            public void onDrawerClosed(View view) {
                getActionBar().setTitle(mTitle);
                // calling onPrepareOptionsMenu() to show action bar icons
                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                getActionBar().setTitle(mDrawerTitle);
                // calling onPrepareOptionsMenu() to hide action bar icons
                invalidateOptionsMenu();
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);

        if (savedInstanceState == null) {
            // on first time display view for first nav item
            displayView(0);
        }
    }

    /**
     * Slide menu item click listener
     * */
    private class SlideMenuClickListener implements
            ListView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            // display view for selected nav drawer item
            displayView(position);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // toggle nav drawer on selecting action bar app icon/title
        if (mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        // Handle action bar actions click
        switch (item.getItemId()) {
        case R.id.action_settings:
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

    /* *
     * Called when invalidateOptionsMenu() is triggered
     */
    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // if nav drawer is opened, hide the action items
        boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
        menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
        return super.onPrepareOptionsMenu(menu);
    }

    /**
     * Diplaying fragment view for selected nav drawer list item
     * */
    private void displayView(int position) {
        // update the main content by replacing fragments
        Fragment fragment = null;
        switch (position) {
        case 0:
            fragment = new HomeFragment();
            break;
        case 1:
            fragment = new FindPeopleFragment();
            break;
        case 2:
            fragment = new MapsFragment();
            break;
        case 3:
            fragment = new CommunityFragment();
            break;
        case 4:
            fragment = new PagesFragment();
            break;
        case 5:
            fragment = new WhatsHotFragment();
            break;

        default:
            break;
        }

        if (fragment != null) {
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction()
                    .replace(R.id.frame_container, fragment).commit();

            // update selected item and title, then close the drawer
            mDrawerList.setItemChecked(position, true);
            mDrawerList.setSelection(position);
            setTitle(navMenuTitles[position]);
            mDrawerLayout.closeDrawer(mDrawerList);
        } else {
            // error in creating fragment
            Log.e("MainActivity", "Error in creating fragment");
        }
    }

    @Override
    public void setTitle(CharSequence title) {
        mTitle = title;
        getActionBar().setTitle(mTitle);
    }

    /**
     * When using the ActionBarDrawerToggle, you must call it during
     * onPostCreate() and onConfigurationChanged()...
     */

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        mDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // Pass any configuration change to the drawer toggls
        mDrawerToggle.onConfigurationChanged(newConfig);
    }

}

[/code]

Buda mapsFragmentin XML kısmı 

[code]

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <fragment
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.google.android.gms.maps.SupportMapFragment" />
      <Button
        android:id="@+id/btnRefresh"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
           android:background="@drawable/ic_action_refresh"/>

</RelativeLayout>

[/code]

Ve arkadaşlar buda manifest

[code]

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.stackcuriosity.curiosity"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"   />
    
    
    
    
    <!-- Harita verisini indirebilmek için izinler -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
     
    <!-- Cihazdan Google Servislerine erişmek için izin -->
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
 
    <!-- İndirilenlerin tutulması için izinler -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 
    <!-- OpenGL ES 2.0 Google Maps Android API v2 için gerekiyor -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/AppTheme" 
         android:configChanges="keyboardHidden|orientation"
        android:label="@string/app_name" >
        
         <!-- Google Maps için API anahtarı-->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyCkT8TxrTxfL-tAwBERI3tS5tFE1aLAqEU" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
 
         
        
        <activity
            android:name=".Login"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>        
               
        
       
        
        
        
        <activity 
            android:name="com.stackcuriosity.slidingmenu.MainActivity"
            android:label="@string/app_name" >            
               <intent-filter>
                <action android:name="android.intent.action.MAINACTIVITY" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            </activity>
            
           
             <activity
            android:name="com.stackcuriosity.slidingmenu.MapsFragment"
            android:label="Maps Products" >
        </activity>
            
        <!-- All Product Activity -->
        <activity
            android:name=".AllProductsActivity"
            android:label="All Products" >
        </activity>

        <!-- Add Product Activity -->
        <activity
            android:name=".NewProductActivity"
            android:label="Add New Product" >
        </activity>
        
         <activity
            android:name=".MainScreenActivity"
            android:label="Main Screen Activity" >
         
        </activity>

        <!-- Edit Product Activity -->
        <activity
            android:name=".EditProductActivity"
            android:label="Edit Product" >
        </activity>
        
      
         <activity android:name=".Register"
                  android:label="@string/app_name">

        </activity>

        <activity android:name=".Registered"
                  android:label="@string/app_name">

        </activity>


        <activity android:name=".Main"
                  android:label="Learn2Crack USER PANEL">

        </activity>
       
        <activity android:name=".PasswordReset"
                  android:label="@string/app_name">

        </activity>
        <activity android:name=".ChangePassword"
                  android:label="@string/app_name">

        </activity>
    </application>

</manifest>

[/code]

17 Görüntülenme

1 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-7661-1418285218.jpg
zafermuhammed93
06.08.2014 - 12:09

hocam öyle de denedm başka bi çalışmada ama skıntı bu sefer              googleHarita = ((SupportMapFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); da

 

 

burda nullpoint exeption atıyr bu bunun la uraştm harita konusnda pek bilgm yoktu araştrmama ragmen sonuc bulamadm  tine aynı şeklde yine şuanki uraştm tarz biraz daha mantıklı geldi. 

 

Ulaş Sancak
06.08.2014 - 12:13
Google Play Services güncel olmadığı için de olabilirmiş.